﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;

namespace ServiceOperater.Helpers
{
    public static class ReflectHelper
    {
        public static FieldInfo getInstanceField(string fieldName)
        {
            // https://stackoverflow.com/questions/1155529/not-getting-fields-from-gettype-getfields-with-bindingflag-default

            // 扩展方法怎么写来着？？？？

            // 自身的实例私有字段
            //   BindingFlags.NonPublic | BindingFlags.Instance

            //  BindingFlags.Public | BindingFlags.NonPublic |  BindingFlags.Static | BindingFlags.Instance |  BindingFlags.DeclaredOnly
            return null;
        }


        // https://stackoverflow.com/questions/7598968/getting-the-name-of-a-field-in-c-sharp
        /// <summary>
        /// 获取字段的名称
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="memberAccess"></param>
        /// <returns></returns>
        public static string GetMemberName<T, TValue>(Expression<Func<T, TValue>> memberAccess)
        {
            //Sample
            //var fieldName = GetMemberName((MyClass c) => c.Field);
            //var propertyName = GetMemberName((MyClass c) => c.Property);
            return ((MemberExpression)memberAccess.Body).Member.Name;
        }
    }
}
